﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DiArte.Data.Catalog
{
    public class ProductPriceDal : BaseDal
    {
        /// <summary>
        /// Deletes all products prices
        /// </summary>
        public void DeleteAll()
        {
            using (var command = new Npgsql.NpgsqlCommand("DELETE FROM product_price"))
                PerformCommand(command);
        }

        /// <summary>
        /// Inserts a new product price
        /// </summary>
        /// <param name="productId">The product id</param>
        /// <param name="storeId">The store id</param>
        /// <param name="value">The price value</param>
        /// <param name="currency">The price currency</param>
        public void Insert(int productId, int storeId, double value, String currency)
        {
            using (var command = new Npgsql.NpgsqlCommand("INSERT INTO product_price(product_price_id, product_id, store_id, value, currency) VALUES " +
                "(nextval('product_price_id_sequence'), :product_id, :store_id, :value, :currency)"))
            {
                command.Parameters.AddWithValue("product_id", productId);
                command.Parameters.AddWithValue("store_id", storeId);
                command.Parameters.AddWithValue("value", value);
                command.Parameters.AddWithValue("currency", currency);

                PerformCommand(command);
            }
        }

    }
}
